import { request } from "./http-base";
import { getOrderList as getOrderListUrl } from "../apis/index";

interface PageInfo {
  page: number; // 页码
  size: number; // 条数
}

interface OrderItem {
  confirmTime: string;
  consignee: {
    address: string;
    name: string;
    phone: string;
    postalCode: string;
  };
  createDateTime: string;
  customerId: number;
  deliveryTime: string;
  id: number;
  lastUpdateTime: string;
  logistics: {
    companyName: string;
    number: string;
  };
  orderNumber: string;
  orderProducts: [
    {
      createDateTime: string;
      id: number;
      lastUpdateTime: string;
      productCount: number;
      productId: number;
      productMedia: {
        type: string;
        url: string;
      };
      productName: string;
      productPrice: {
        money: number;
        points: number;
      };
      productType: string;
    }
  ];
  orderTime: string;
  payStatus: string;
  payTime: string;
  remark: string;
  status: string;
  totalPrice: {
    money: number;
    points: number;
  };
}

interface OrderList {
  records: OrderItem[];
  total: number;
  totalPage: number;
}

export const getOrderList = async (params: PageInfo): Promise<OrderList> => {
  const res = await request(getOrderListUrl, params, "GET");
  return (
    res?.data?.data || {
      records: [],
      total: 0,
      totalPage: 1
    }
  );
};
